declare let JIM: any;
module MC.Call {

    /** 极光的用户名 */
    let uid: string;
    let pass: string;
    let LoadFun: Function = null;
    export function Jiguang(_fun: Function) {
        LoadFun = _fun;
        window.JIM = new JMessage({
            debug: false//true
        });
        MC.api('getjiguang', {}, (data: any) => {
            uid = data[4]
          ///  MC.user.getInfo(this.uid);
            pass = data[5];
            JiguangInit(data[0], data[1], data[2], data[3]);
            ///	console.log(data);
        });
    }
    function JiguangInit(appkey: string, random_str: string, timestamp: string, signature: string) {
        JIM.init({
            "appkey": appkey,
            "random_str": random_str,
            "signature": signature,
            "timestamp": timestamp,
            "flag": 1
        }).onSuccess(function (data: any) {
            console.log('success:', uid);
            JIM.login({
                'username': uid,
                'password': pass
            }).onSuccess(function (data: any) {
                LoadFun && LoadFun(uid,data);
            });
        }).onFail(function (data: any) {
            console.log('error:', data);
        });
    }
}